package com.credithc.customers.dataservice.service.impl;

import com.credithc.baseserv.core.utils.UUIDUtils;
import com.credithc.customers.base.constants.CustomerConstants;
import com.credithc.customers.base.mapper.CustomerProductMapper;
import com.credithc.customers.base.mapper.CustomerRelationInfoMapper;
import com.credithc.customers.base.po.CompanyIdInfoPo;
import com.credithc.customers.base.po.CustomerIdInfoPo;
import com.credithc.customers.base.po.CustomerProductInfoPo;
import com.credithc.customers.base.po.CustomerRelationInfoPo;
import com.credithc.customers.base.service.ICommonService;
import com.credithc.customers.base.utils.CustomerUtils;
import com.credithc.customers.dataservice.constants.SyncTypeEnum;
import com.credithc.customers.dataservice.constants.TableNameConstants;
import com.credithc.customers.dataservice.mapper.BDB.HhrbCustomMapper;
import com.credithc.customers.dataservice.mapper.BDB.HrhbOrderToCustomMapper;
import com.credithc.customers.dataservice.mapper.BDB.HrhbSubOrderMapper;
import com.credithc.customers.dataservice.mapper.BDB.YztCustomMapper;
import com.credithc.customers.dataservice.mapper.BXHX.SalePolicyProMapper;
import com.credithc.customers.dataservice.mapper.BXHX.YztSyncUserMapper;
import com.credithc.customers.dataservice.mapper.CD.*;
import com.credithc.customers.dataservice.mapper.DLR.DlrMapper;
import com.credithc.customers.dataservice.mapper.GD.CrmAccountMesDkMapper;
import com.credithc.customers.dataservice.mapper.GD.CrmClientYztMapper;
import com.credithc.customers.dataservice.mapper.GD.CrmIntopiecesDkMapper;
import com.credithc.customers.dataservice.mapper.GD.CrmRepayDkMapper;
import com.credithc.customers.dataservice.mapper.HHRCJD.HHRCFAccountMapper;
import com.credithc.customers.dataservice.mapper.HHRCJD.HHRCFProductMapper;
import com.credithc.customers.dataservice.mapper.HYD.HydMapper;
import com.credithc.customers.dataservice.mapper.HYR.HyrMapper;
import com.credithc.customers.dataservice.mapper.JWBX.JWBXCustomerMapper;
import com.credithc.customers.dataservice.mapper.JWBX.JWBXinsurdBackMapper;
import com.credithc.customers.dataservice.mapper.XHQB.XhqbMapper;
import com.credithc.customers.dataservice.mapper.XHQB2.Xhqb2Mapper;
import com.credithc.customers.dataservice.po.*;
import com.credithc.customers.dataservice.ro.BinlogColumnRo;
import com.credithc.customers.dataservice.ro.BinlogRo;
import com.credithc.customers.dataservice.ro.CustomerAccountInfoRo;
import com.credithc.customers.dataservice.ro.CustomerProductInfoRo;
import com.credithc.customers.dataservice.service.CustomerProductInfoService;
import com.credithc.customers.dataservice.service.SyncDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class CustomerProductInfoServiceImpl implements CustomerProductInfoService {

    @Autowired
    private ICommonService commonService;
    @Autowired
    private DlrMapper dlrMapper;
    @Autowired
    private HyrMapper hyrMapper;
    @Autowired
    private Xhqb2Mapper xhqb2Mapper;
    @Autowired
    private XhqbMapper xhqbOrderMapper;
    @Autowired
    private HydMapper hydMapper;
    @Autowired
    private CrmAccountMesDkMapper crmAccountMesDkMapper;
    @Autowired
    private CrmIntopiecesDkMapper crmIntopiecesDkMapper;
    @Autowired
    private CrmRepayDkMapper crmRepayDkMapper;
    @Autowired
    private CrmClientYztMapper crmClientYztMapper;
    @Autowired
    private HrhbOrderToCustomMapper hrhbOrderToCustomMapper;
    @Autowired
    private HhrbCustomMapper hhrbCustomMapper;
    @Autowired
    private YztCustomMapper yztCustomMapper;
    @Autowired
    private HrhbSubOrderMapper hrhbSubOrderMapper;
    @Autowired
    SyncDataService syncDataService;
    @Autowired
    private CustomerRelationInfoMapper customerRelationInfoMapper;
    @Autowired
    private LesseeMapper lesseeMapper;
    @Autowired
    private ContractLoanMapper contractLoanMapper;
    @Autowired
    private ContractMapper contractMapper;
    @Autowired
    private EntryBasicInfoMapper entryBasicInfoMapper;
    @Autowired
    private EntryProdInfoMapper entryProdInfoMapper;
    @Autowired
    private SalePolicyProMapper salePolicyProMapper;
    @Autowired
    private YztSyncUserMapper yztSyncUserMapper;
    @Autowired
    private CustomerProductMapper customerProductMapper;
    @Autowired
    private JWBXCustomerMapper jwbxCustomerMapper;
    @Autowired
    private JWBXinsurdBackMapper jwbXinsurdBackMapper;
    @Autowired
    private HHRCFProductMapper hhrcfProductMapper;
    @Autowired
    private HHRCFAccountMapper hhrcfAccountMapper;

    @Override
    public CustomerProductInfoRo bulidDlrCustomerProduct(BinlogRo binlogRo) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            initDlrCustomerProductInfoRo(beforeColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.UPDATE.getValue().equals(eventType)){
            initDlrCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.NEW.getValue().equals(eventType)){
            initDlrCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }

        return customerProductInfoRo;
    }

    @Override
    public CustomerProductInfoRo bulidHyrFixCustomerProduct(BinlogRo binlogRo) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            initHyrFixCustomerProductInfoRo(beforeColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.UPDATE.getValue().equals(eventType)){
            initHyrFixCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.NEW.getValue().equals(eventType)){
            initHyrFixCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }


        return customerProductInfoRo;
    }
    @Override
    public CustomerProductInfoRo bulidHydCustomerProduct(BinlogRo binlogRo) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            initHydCustomerProductInfoRo(beforeColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.UPDATE.getValue().equals(eventType)){
            initHydCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.NEW.getValue().equals(eventType)){
            initHydCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }


        return customerProductInfoRo;
    }

    @Override
    public CustomerProductInfoRo bulidXhqbCustomerProduct(BinlogRo binlogRo) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            initXhqbCustomerProductInfoRo(beforeColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.UPDATE.getValue().equals(eventType)){
            initXhqbCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.NEW.getValue().equals(eventType)){
            initXhqbCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }


        return customerProductInfoRo;
    }

    @Override
    public CustomerProductInfoRo bulidGdCustomerProduct(BinlogRo binlog) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlog.getSchemaName());
        customerProductInfoRo.setTableName(binlog.getTableName());
        String eventType = binlog.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlog.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlog.getRows().getBeforeColumns();
        Map<String,String> afterMap = new HashMap<>();
        Map<String,String> beforeMap = new HashMap<>();
        for (BinlogColumnRo b: afterColumns) {
            afterMap.put(b.getName(),(String) b.getValue());
        }
        for (BinlogColumnRo b: beforeColumns) {
            beforeMap.put(b.getName(),(String)b.getValue());
        }
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            initGdCustomerProduct(customerProductInfoRo,beforeMap);
        }
        if (SyncTypeEnum.UPDATE.getValue().equals(eventType)){

            initGdCustomerProduct(customerProductInfoRo,afterMap);
        }
        if (SyncTypeEnum.NEW.getValue().equals(eventType)){
           // initGdCustomerProduct(customerProductInfoRo,afterMap);
            return null;
        }

        return customerProductInfoRo;
    }

    @Override
    public CustomerProductInfoRo newGdCustomerProduct(BinlogRo binlogRo) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(TableNameConstants.GD_JJ);
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        Map<String,String> afterMap = new HashMap<>();
        Map<String,String> beforeMap = new HashMap<>();
        for (BinlogColumnRo b: afterColumns) {
            afterMap.put(b.getName(),(String) b.getValue());
        }
        for (BinlogColumnRo b: beforeColumns) {
            beforeMap.put(b.getName(),(String)b.getValue());
        }
       if (StringUtils.isNotBlank(afterMap.get("knnent_id")) && !"0".equals(afterMap.get("knnent_id")) && !afterMap.get("knnent_id").equals(beforeMap.get("knnent_id"))){
           customerProductInfoRo.setSyncType(SyncTypeEnum.NEW.getValue());
           initNewCustomerProduct(customerProductInfoRo,afterMap);
           return customerProductInfoRo;
       }
        return null;
    }

    @Override
    public CustomerProductInfoRo updataGdCustomerProduct(BinlogRo binlogRo) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(TableNameConstants.GD_JJ);
        customerProductInfoRo.setSyncType(SyncTypeEnum.UPDATE.getValue());
        customerProductInfoRo.setUserResourceId("个贷表里没有用户id");
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        Map<String,String> afterMap = new HashMap<>();
        for (BinlogColumnRo b: afterColumns) {
            afterMap.put(b.getName(),(String) b.getValue());
        }
        String acountId = afterMap.get("id");
        CrmAccountMesDkPO crmAccountMesDkPO = null;
        CrmIntopiecesDkPO crmIntopiecesDkPO = null;
        try {
            Example example = new Example(CrmAccountMesDkPO.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id",acountId);
            crmAccountMesDkPO = crmAccountMesDkMapper.selectOneByExample(example);
            Example example1 = new Example(CrmIntopiecesDkPO.class);
            Example.Criteria criteria1 = example1.createCriteria();
            criteria1.andEqualTo("id",crmAccountMesDkPO.getIntopiecesId());
            crmIntopiecesDkPO = crmIntopiecesDkMapper.selectOneByExample(example1);
        } catch (Exception e) {
            log.error(e.getMessage());
            return null;
        }

        CrmRepayDkPO crmRepayDkPO = null;
        Example example = new Example(CrmIntopiecesInfoDkPO.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("intopiecesId",crmIntopiecesDkPO.getId());
        customerProductInfoRo.setTableKey(crmIntopiecesDkPO.getId());
        CrmIntopiecesInfoDkPO crmClientYztPO = crmClientYztMapper.selectOneByExample(example);
        if (crmAccountMesDkPO!=null){
            Example example1 = new Example(CrmRepayDkPO.class);
            Example.Criteria criteria1 = example1.createCriteria();
            criteria1.andEqualTo("contractId",crmAccountMesDkPO.getId());
            crmRepayDkPO = crmRepayDkMapper.selectOneByExample(example1);
            Integer status = null;
            if (crmRepayDkPO != null){
                status = crmRepayDkPO.getStatus();
            }
            Integer state = crmIntopiecesDkPO.getState();

            customerProductInfoRo.setProductNo(crmIntopiecesDkPO.getLoanType());
            bulidGDProductStatus(customerProductInfoRo,state,status);
            Integer sys = crmIntopiecesDkPO.getPiecesType();
            bulidGdSystemSign(sys,customerProductInfoRo,crmAccountMesDkPO.getAccountType(),crmAccountMesDkPO.getIsTrust(),crmAccountMesDkPO.getIsNewPlatform());
            customerProductInfoRo.setProductAmount(crmIntopiecesDkPO.getCount());
            if (crmAccountMesDkPO != null) {
                try {
                    customerProductInfoRo.setProductDeadline(crmAccountMesDkPO.getLoan_qishu()*30+"");
                } catch (Exception e) {
                   // e.printStackTrace();
                }
                customerProductInfoRo.setProductEndTime(new Timestamp(crmAccountMesDkPO.getRepayEndTime()*1000));
                customerProductInfoRo.setProductStartTime(new Timestamp(crmAccountMesDkPO.getRepayStartTime()*1000));
                customerProductInfoRo.setProductAmount(crmAccountMesDkPO.getAccountMoney());
            }
            if (crmClientYztPO !=null){
                customerProductInfoRo.setPreCustomerNo(crmClientYztPO.getClientId());
                customerProductInfoRo.setCustomerNo(crmClientYztPO.getKnnentId());
            }
            customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
            customerProductInfoRo.setCustomerRole(CustomerConstants.CUSTOMER_ACCOUNT_TYPE_LOAN);
        }

        return customerProductInfoRo;
    }

    @Override
    public CustomerProductInfoRo repayGdCustomerProduct(BinlogRo binlogRo) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(TableNameConstants.GD_JJ);
        customerProductInfoRo.setSyncType(SyncTypeEnum.UPDATE.getValue());
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        Map<String,String> afterMap = new HashMap<>();
        for (BinlogColumnRo b: afterColumns) {
            afterMap.put(b.getName(),(String) b.getValue());
        }
        String contract_id = afterMap.get("contract_id");
        CrmAccountMesDkPO crmAccountMesDkPO = null;
        CrmIntopiecesDkPO crmIntopiecesDkPO = null;
        try {
            Example example = new Example(CrmAccountMesDkPO.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id",contract_id);
            crmAccountMesDkPO = crmAccountMesDkMapper.selectOneByExample(example);
            Example example1 = new Example(CrmIntopiecesDkPO.class);
            Example.Criteria criteria1 = example1.createCriteria();
            criteria1.andEqualTo("id",crmAccountMesDkPO.getIntopiecesId());
            crmIntopiecesDkPO = crmIntopiecesDkMapper.selectOneByExample(example1);
        } catch (Exception e) {
            log.error(e.getMessage());
            return null;
        }
        CrmRepayDkPO crmRepayDkPO = null;
        Example example = new Example(CrmIntopiecesInfoDkPO.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("intopiecesId",crmIntopiecesDkPO.getId());
        customerProductInfoRo.setTableKey(crmIntopiecesDkPO.getId());
        CrmIntopiecesInfoDkPO crmClientYztPO = crmClientYztMapper.selectOneByExample(example);
        if (crmAccountMesDkPO!=null){
            Example example1 = new Example(CrmRepayDkPO.class);
            Example.Criteria criteria1 = example1.createCriteria();
            criteria1.andEqualTo("contractId",crmAccountMesDkPO.getId());
            crmRepayDkPO = crmRepayDkMapper.selectOneByExample(example1);
            Integer status = null;
            if (crmRepayDkPO != null){
                status = crmRepayDkPO.getStatus();
            }
            Integer state = crmIntopiecesDkPO.getState();

            customerProductInfoRo.setProductNo(crmIntopiecesDkPO.getLoanType());
            bulidGDProductStatus(customerProductInfoRo,state,status);
            Integer sys = crmIntopiecesDkPO.getPiecesType();
            bulidGdSystemSign(sys,customerProductInfoRo,crmAccountMesDkPO.getAccountType(),crmAccountMesDkPO.getIsTrust(),crmAccountMesDkPO.getIsNewPlatform());
           // customerProductInfoRo.setProductSourceSystem(CustomerConstants.GD+"");
            customerProductInfoRo.setProductAmount(crmIntopiecesDkPO.getCount());
            if (crmAccountMesDkPO != null) {
                try {
                    customerProductInfoRo.setProductDeadline(crmAccountMesDkPO.getLoan_qishu()*30+"");
                } catch (Exception e) {

                }
                customerProductInfoRo.setProductEndTime(new Timestamp(crmAccountMesDkPO.getRepayEndTime()*1000));
                customerProductInfoRo.setProductStartTime(new Timestamp(crmAccountMesDkPO.getRepayStartTime()*1000));
                customerProductInfoRo.setProductAmount(crmAccountMesDkPO.getAccountMoney());
            }
            if (crmClientYztPO !=null){
                customerProductInfoRo.setPreCustomerNo(crmClientYztPO.getClientId());
                customerProductInfoRo.setCustomerNo(crmClientYztPO.getKnnentId());
            }
            customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
            customerProductInfoRo.setCustomerRole(CustomerConstants.CUSTOMER_ACCOUNT_TYPE_LOAN);
        }
        customerProductInfoRo.setUserResourceId("个贷表里没有用户id");
        return customerProductInfoRo;
    }

    @Override
    public void buildBDBCustomerProduct(BinlogRo binlogRo) {

        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        Map<String ,String> map = new HashMap<>();
        for (BinlogColumnRo bc: afterColumns) {
            map.put(bc.getName(), (String) bc.getValue());
            if ("policyno".equals(bc.getName()) && StringUtils.isBlank((String) bc.getValue())){
                return;
            }
        }
        initBDBCustomerProduct(customerProductInfoRo,map);
    }

    @Override
    public void bulidFundData(BinlogRo binlogRo) {
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        Map<String ,String> map = new HashMap<>();
        for (BinlogColumnRo bc: afterColumns) {
            map.put(bc.getName(), (String) bc.getValue());
        }
        Map<String ,String> beforemap = new HashMap<>();
        for (BinlogColumnRo bc: beforeColumns) {
            beforemap.put(bc.getName(), (String) bc.getValue());
        }

        //订单信息
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        customerProductInfoRo.setSubSystemSign("FUND");
        customerProductInfoRo.setSystemSign("FUND");
        customerProductInfoRo.setProductSourceSystem("18");

        String fund_manager = map.get("fund_manager");
        if (StringUtils.isNotBlank(fund_manager)){
            if (fund_manager.indexOf("坤元")!= -1){
                customerProductInfoRo.setSubSystemSign("KYZC");
                customerProductInfoRo.setProductSourceSystem("8");
            }else if (fund_manager.indexOf("蓝枫")!=-1){
                customerProductInfoRo.setSubSystemSign("LFJJ");
                customerProductInfoRo.setProductSourceSystem("10");
            }else if (fund_manager.indexOf("昌泽")!= -1){
                customerProductInfoRo.setSubSystemSign("CZJJ");
                customerProductInfoRo.setProductSourceSystem("9");
            }
        }
        customerProductInfoRo.setProductStatus(6);

        customerProductInfoRo.setProductStartTime(CustomerUtils.dateStr2Timestamp(map.get("sign_date")));
        customerProductInfoRo.setProductNo(map.get("fund_id"));
        customerProductInfoRo.setTableKey(map.get("id"));
        customerProductInfoRo.setProductDeadline(map.get("product_deadline"));
        //投资人
        customerProductInfoRo.setCustomerRole("1");
        customerProductInfoRo.setProductAmount(new BigDecimal(map.get("actual_amount")));
        String card_type = map.get("card_type");
        if (StringUtils.isNotBlank(card_type)){
            if (card_type.indexOf("身份证")!= -1){
                card_type = "1";
            }else if (card_type.indexOf("护照")!= -1){
                card_type = "2";
            }else if (card_type.indexOf("回乡证")!= -1){
                card_type = "3";
            }else if (card_type.indexOf("居留证")!= -1){
                card_type = "4";
            }else if (card_type.indexOf("军官证")!=-1){
                card_type = "5";
            }else if (card_type.indexOf("营业执照") != -1){
                CompanyIdInfoPo card_no = commonService.getCompanyInfo(map.get("card_no"), null, null, null);
                if (card_no == null){
                    card_no = commonService.getCompanyInfo(null,map.get("card_no"),  null, null);
                }
                if (card_no!=null) {
                    customerProductInfoRo.setUserResourceId("FUND" + card_no.getCustomerNo());
                    customerProductInfoRo.setCustomerNo(card_no.getCustomerNo());
                }
            }
        }
        if (StringUtils.isBlank(customerProductInfoRo.getCustomerNo())) {
            CustomerIdInfoPo existCustomerInfo = commonService.getExistCustomerInfo(map.get("customer_name"), card_type, map.get("card_no"));
            if (existCustomerInfo != null) {
                customerProductInfoRo.setUserResourceId("FUND" + existCustomerInfo.getCustomerNo());
                customerProductInfoRo.setCustomerNo(existCustomerInfo.getCustomerNo());
            }
        }
        if (StringUtils.isNotBlank(customerProductInfoRo.getCustomerNo())){
            syncDataService.syncCustomerProduct(customerProductInfoRo);
        }

        //账户信息
        CustomerAccountInfoRo customerAccountInfoRo = new CustomerAccountInfoRo();
        customerAccountInfoRo.setSyncType(eventType);
        customerAccountInfoRo.setSubSystemSign("FUND");
        customerAccountInfoRo.setSystemSign("FUND");
        if (StringUtils.isNotBlank(fund_manager)){
            if (fund_manager.indexOf("坤元")!= -1){
                customerAccountInfoRo.setSubSystemSign("KYZC");
            }else if (fund_manager.indexOf("蓝枫")!=-1){
                customerAccountInfoRo.setSubSystemSign("LFJJ");
            }else if (fund_manager.indexOf("昌泽")!= -1){
                customerAccountInfoRo.setSubSystemSign("CZJJ");
            }
        }
        customerAccountInfoRo.setAccountNo(map.get("bank_card"));
        customerAccountInfoRo.setAccountType(CustomerConstants.CUSTOMER_ACCOUNT_TYPE_BANK_CARD);
        customerAccountInfoRo.setUserSourceId(customerProductInfoRo.getUserResourceId());
        customerAccountInfoRo.setCustomerNo(customerProductInfoRo.getCustomerNo());
        customerAccountInfoRo.setAccountCreateTime(customerProductInfoRo.getProductStartTime());
        customerAccountInfoRo.setAccountStatus(CustomerConstants.STATUS_ACCOUNT_AVAILABLE);
        if(SyncTypeEnum.UPDATE.getValue().equals(eventType)){
            if(!beforemap.get("bank_card").equals(map.get("bank_card"))){
                customerAccountInfoRo.setOldAccountNo(beforemap.get("bank_card"));
            }
        }
        if(StringUtils.isNotBlank(customerAccountInfoRo.getCustomerNo()) && StringUtils.isNotBlank(customerAccountInfoRo.getAccountNo()) && !SyncTypeEnum.DELETE.getValue().equals(eventType)) {
            syncDataService.syncCustomerAccount(customerAccountInfoRo);
        }
    }
    @Override
    public void bulidBXHXData(BinlogRo binlogRo) {
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        Map<String ,String> map = new HashMap<>();
        for (BinlogColumnRo bc: afterColumns) {
            map.put(bc.getName(), (String) bc.getValue());
        }
        Map<String ,String> beforemap = new HashMap<>();
        for (BinlogColumnRo bc: beforeColumns) {
            beforemap.put(bc.getName(), (String) bc.getValue());
        }

        //订单信息
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            map = beforemap;
        }
        customerProductInfoRo.setSubSystemSign("BXHX");
        customerProductInfoRo.setSystemSign("BX");
        customerProductInfoRo.setProductSourceSystem("20");
        customerProductInfoRo.setProductStatus(getYZTStatus("BXHX"+map.get("policy_status")));
        customerProductInfoRo.setProductStartTime(CustomerUtils.dateStr2Timestamp(map.get("effective_date")));
        customerProductInfoRo.setProductEndTime(CustomerUtils.dateStr2Timestamp(map.get("policy_validity_date")));
        if (customerProductInfoRo.getProductStartTime()!=null && customerProductInfoRo.getProductEndTime() != null){
            int deadLine = (int) ((customerProductInfoRo.getProductEndTime().getTime() - customerProductInfoRo.getProductStartTime().getTime()) / (1000 * 3600 * 24));
            customerProductInfoRo.setProductDeadline(deadLine + "");
        }
        customerProductInfoRo.setTableKey(map.get("id"));
        String tbrId = map.get("applicant_idcard");
        String tbrType = map.get("applicant_cardtype");
        String tbrName = map.get("applicant_name");
        if (StringUtils.isNotBlank(tbrId)) {
            //查询投保人信息
            Example tbE = new Example(BxhxYztPO.class);
            Example.Criteria tbC = tbE.createCriteria();
            tbC.andEqualTo("cardid", tbrId);
            tbC.andEqualTo("cardType",tbrType);
            tbC.andEqualTo("name",tbrName);
            BxhxYztPO bxhxYztPO = yztSyncUserMapper.selectOneByExample(tbE);
            if (bxhxYztPO !=null && StringUtils.isNotBlank(bxhxYztPO.getCustomerNo()) ){
                customerProductInfoRo.setUserResourceId("BXHX" + bxhxYztPO.getCustomerNo());
                customerProductInfoRo.setCustomerNo(bxhxYztPO.getCustomerNo());
               // customerProductInfoRo.setCustomerRole("3");
                //查产品保单关联表
                Example policyProE = new Example(BXHXSalePolicyProPO.class);
                Example.Criteria policyProC = policyProE.createCriteria();
                policyProC.andEqualTo("policyId",map.get("id"));
                List<BXHXSalePolicyProPO> bxhxSalePolicyProPOS = salePolicyProMapper.selectByExample(policyProE);
                //保存投保人角色
                for (BXHXSalePolicyProPO b:bxhxSalePolicyProPOS) {
                    Integer pronum = b.getPronum();
                    if (pronum >= 1) {
                        customerProductInfoRo.setProductAmount(BigDecimal.valueOf(b.getScalePremium()/pronum));
                        customerProductInfoRo.setProductNo(b.getProId() + "");
                        for (int i = pronum;i>0;i--){
                            customerProductInfoRo.setTableKey(b.getId()+"_"+i);
                            if (b.getDr() == 1){
                                customerProductInfoRo.setSyncType(SyncTypeEnum.DELETE.getValue());
                            }
                            syncDataService.syncCustomerProduct(customerProductInfoRo);
                        }
                    }
                }
                if (customerProductInfoRo.getSyncType().equals(SyncTypeEnum.DELETE.getValue())||customerProductInfoRo.getProductStatus() == 2||customerProductInfoRo.getProductStatus() == 5 || customerProductInfoRo.getProductStatus() == 7 ) {
                    //根据订单信息修改角色可用性
                    Example example = new Example(CustomerProductInfoPo.class);
                    Example.Criteria criteria = example.createCriteria();
                    // criteria.andEqualTo("customerRole","3");
                    criteria.andEqualTo("subSystemSign",customerProductInfoRo.getSubSystemSign());
                    criteria.andEqualTo("customerNo",customerProductInfoRo.getCustomerNo());
                    List<Integer> list = new ArrayList(3);
                    list.add(2);
                    list.add(5);
                    list.add(7);
                    criteria.andNotIn("productStatus",list);
                    int i = customerProductMapper.selectCountByExample(example);
                    if (i<1) {
                        customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_UNEFFECTIVE);
                    }
                }
                syncDataService.addRoleInfo(customerProductInfoRo.getUserResourceId(), customerProductInfoRo.getCustomerNo(), customerProductInfoRo.getSystemSign(), customerProductInfoRo.getSubSystemSign(), "3", customerProductInfoRo.getCustomerRoleStatus());

                //保存银行卡信息
                CustomerAccountInfoRo customerAccountInfoRo = new CustomerAccountInfoRo();
                customerAccountInfoRo.setSyncType(eventType);
                customerAccountInfoRo.setSubSystemSign("BXHX");
                customerAccountInfoRo.setSystemSign("BX");
                customerAccountInfoRo.setAccountNo(map.get("bank_account"));
                customerAccountInfoRo.setAccountType(CustomerConstants.CUSTOMER_ACCOUNT_TYPE_BANK_CARD);
                customerAccountInfoRo.setUserSourceId(customerProductInfoRo.getUserResourceId());
                customerAccountInfoRo.setCustomerNo(customerProductInfoRo.getCustomerNo());
                customerAccountInfoRo.setAccountCreateTime(customerProductInfoRo.getProductStartTime());
                customerAccountInfoRo.setAccountStatus(CustomerConstants.STATUS_ACCOUNT_AVAILABLE);
                if(SyncTypeEnum.UPDATE.getValue().equals(eventType)){
                    if(!beforemap.get("bank_account").equals(map.get("bank_account"))){
                        customerAccountInfoRo.setOldAccountNo(beforemap.get("bank_account"));
                    }
                }
                if(StringUtils.isNotBlank(customerAccountInfoRo.getCustomerNo()) && StringUtils.isNotBlank(customerAccountInfoRo.getAccountNo())&& !SyncTypeEnum.DELETE.getValue().equals(eventType)) {
                    syncDataService.syncCustomerAccount(customerAccountInfoRo);
                }
                //保存被保人角色
                String bbrId = map.get("recognizee_idcard");
                String bbrType = map.get("recognizee_cardtype");
                String bbrName = map.get("recognizee_name");
                if (StringUtils.isNotBlank(bbrId)){
                    //查询被保人客户号
                    Example bbE = new Example(BxhxYztPO.class);
                    Example.Criteria bbC = bbE.createCriteria();
                    bbC.andEqualTo("cardid", bbrId);
                    bbC.andEqualTo("cardType",bbrType);
                    bbC.andEqualTo("name",bbrName);
                    BxhxYztPO bbr = yztSyncUserMapper.selectOneByExample(bbE);
                    if (bbr!=null && StringUtils.isNotBlank(bbr.getCustomerNo())){
                        //增加被保人角色
                        syncDataService.addRoleInfo("BXHX"+bbr.getCustomerNo(),bbr.getCustomerNo(),"BX","BXHX","4",CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);

                        //保存关系信息
                        CustomerRelationInfoPo customerRelationInfoPo = new CustomerRelationInfoPo();
                        customerRelationInfoPo.setRelationId("tbBXHX"+bxhxYztPO.getCustomerNo()+"bbBXHX"+bbr.getCustomerNo());
                        customerRelationInfoPo.setCustomerNo(bxhxYztPO.getCustomerNo());
                        customerRelationInfoPo.setRoleInRelation(2);
                        CustomerRelationInfoPo customerRelationInfoPo1 = customerRelationInfoMapper.selectOne(customerRelationInfoPo);
                        if (customerRelationInfoPo1 == null) {
                            customerRelationInfoPo.setId(UUIDUtils.getUUID());
                            customerRelationInfoPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
                            customerRelationInfoPo.setSubSystemSign("BXHX");
                            customerRelationInfoPo.setSystemSign("BX");
                            customerRelationInfoPo.setRelationId("tbBXHX"+bxhxYztPO.getCustomerNo()+"bbBXHX"+bbr.getCustomerNo());
                            customerRelationInfoPo.setRelationSource(2);
                            customerRelationInfoPo.setRoleInRelation(2);
                            customerRelationInfoMapper.insert(customerRelationInfoPo);
                        }
                        customerRelationInfoPo.setRoleInRelation(3);
                        customerRelationInfoPo.setCustomerNo(bbr.getCustomerNo());
                        CustomerRelationInfoPo customerRelationInfoPo2 = customerRelationInfoMapper.selectOne(customerRelationInfoPo);
                        if (customerRelationInfoPo2 == null) {
                            customerRelationInfoPo.setId(UUIDUtils.getUUID());
                            customerRelationInfoPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
                            customerRelationInfoPo.setSubSystemSign("BXHX");
                            customerRelationInfoPo.setSystemSign("BX");
                            customerRelationInfoPo.setRelationId("tbBXHX"+bxhxYztPO.getCustomerNo()+"bbBXHX"+bbr.getCustomerNo());
                            customerRelationInfoPo.setRelationSource(2);
                            customerRelationInfoPo.setRoleInRelation(3);
                            customerRelationInfoMapper.insert(customerRelationInfoPo);
                        }
                    }
                }
            }
        }
    }

    @Override
    public void bulidChdData(BinlogRo binlogRo) {
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        Map map = new HashMap();
        for (BinlogColumnRo bc: afterColumns) {
            map.put(bc.getName(), (String) bc.getValue());
        }
        Map<String ,String> beforemap = new HashMap<>();
        for (BinlogColumnRo bc: beforeColumns) {
            beforemap.put(bc.getName(), (String) bc.getValue());
        }
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            initCHDCustomerProductInfoRo(beforemap,customerProductInfoRo);
        }
        if (SyncTypeEnum.UPDATE.getValue().equals(eventType)){
            initCHDCustomerProductInfoRo(map,customerProductInfoRo);
        }
        if (SyncTypeEnum.NEW.getValue().equals(eventType)){
            initCHDCustomerProductInfoRo(map,customerProductInfoRo);
        }
    }

    @Override
    public void bulidJwbxOrder(BinlogRo binlogRo) {
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        Map<String ,String> map = new HashMap<>();
        for (BinlogColumnRo bc: afterColumns) {
            map.put(bc.getName(), (String) bc.getValue());
        }
        Map<String ,String> beforemap = new HashMap<>();
        for (BinlogColumnRo bc: beforeColumns) {
            beforemap.put(bc.getName(), (String) bc.getValue());
        }

        //订单信息
        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            map = beforemap;
        }
        customerProductInfoRo.setSubSystemSign("JWBX");
        customerProductInfoRo.setSystemSign("BX");
        customerProductInfoRo.setProductSourceSystem("21");
        customerProductInfoRo.setProductNo(map.get("product_id"));
        customerProductInfoRo.setProductStatus(getYZTStatus("JWBX"+map.get("status")));
        customerProductInfoRo.setProductStartTime(CustomerUtils.dateStr2Timestamp(map.get("sign_time")));
       // customerProductInfoRo.setProductEndTime(CustomerUtils.dateStr2Timestamp(map.get("policy_validity_date")));
        customerProductInfoRo.setProductDeadline(map.get("renewal_period")+"年");
        customerProductInfoRo.setTableKey(map.get("id"));
        customerProductInfoRo.setProductAmount(new BigDecimal(map.get("premium")));
        String tbrId = map.get("card_id");
        String tbrName = map.get("cn_name");
        if (StringUtils.isNotBlank(tbrId)) {
            //查询投保人信息
            Example tbE = new Example(JWBXCusTomerPO.class);
            Example.Criteria tbC = tbE.createCriteria();
            tbC.andEqualTo("cardNo", tbrId);
           // tbC.andEqualTo("name",tbrName);
            JWBXCusTomerPO jwbxCusTomerPO = null;
            try {
                jwbxCusTomerPO = jwbxCustomerMapper.selectOneByExample(tbE);
            } catch (Exception e) {
                //e.printStackTrace();
            }
            if (jwbxCusTomerPO !=null && StringUtils.isNotBlank(jwbxCusTomerPO.getCustomerNo()) ) {
                customerProductInfoRo.setUserResourceId("JWBX" + jwbxCusTomerPO.getCustomerNo());
                customerProductInfoRo.setCustomerNo(jwbxCusTomerPO.getCustomerNo());
                syncDataService.syncCustomerProduct(customerProductInfoRo);

                if (customerProductInfoRo.getSyncType().equals(SyncTypeEnum.DELETE.getValue()) || customerProductInfoRo.getProductStatus() == 2 || customerProductInfoRo.getProductStatus() == 5 || customerProductInfoRo.getProductStatus() == 7) {
                    //根据订单信息修改角色可用性
                    Example example = new Example(CustomerProductInfoPo.class);
                    Example.Criteria criteria = example.createCriteria();
                    // criteria.andEqualTo("customerRole","3");
                    criteria.andEqualTo("subSystemSign", customerProductInfoRo.getSubSystemSign());
                    criteria.andEqualTo("customerNo", customerProductInfoRo.getCustomerNo());
                    List<Integer> list = new ArrayList(3);
                    list.add(2);
                    list.add(5);
                    list.add(7);
                    criteria.andNotIn("productStatus", list);
                    int i = customerProductMapper.selectCountByExample(example);
                    if (i < 1) {
                        customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_UNEFFECTIVE);
                    }
                }
                syncDataService.addRoleInfo(customerProductInfoRo.getUserResourceId(), customerProductInfoRo.getCustomerNo(), customerProductInfoRo.getSystemSign(), customerProductInfoRo.getSubSystemSign(), "3", customerProductInfoRo.getCustomerRoleStatus() == null ? CustomerConstants.STATUS_ACCOUNT_AVAILABLE:customerProductInfoRo.getCustomerRoleStatus());


                Example example = new Example(JWBXInsureBackPo.class);
                Example.Criteria criteria1 = example.createCriteria();
                criteria1.andEqualTo("appointmentId", map.get("appointment_id"));
                JWBXInsureBackPo jwbxInsureBackPo = null;
                try {
                    jwbxInsureBackPo = jwbXinsurdBackMapper.selectOneByExample(example);
                } catch (Exception e) {

                }

                Example example1 = new Example(JWBXCusTomerPO.class);
                Example.Criteria criteria = example1.createCriteria();
                criteria.andEqualTo("cardNo", jwbxInsureBackPo.getCardId());
             //   criteria.andEqualTo("name", jwbxInsureBackPo.getCnName());
               // criteria.andEqualTo("cardType", jwbxInsureBackPo.getCardType());
                JWBXCusTomerPO jwbxCusTomerPO1 = jwbxCustomerMapper.selectOneByExample(example1);
                if (jwbxCusTomerPO1 != null && StringUtils.isNotBlank(jwbxCusTomerPO1.getCustomerNo())) {
                    syncDataService.addRoleInfo("JWBX" + jwbxCusTomerPO1.getCustomerNo(), jwbxCusTomerPO1.getCustomerNo(), customerProductInfoRo.getSystemSign(), customerProductInfoRo.getSubSystemSign(), "4", CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
                    //保存关系信息
                    CustomerRelationInfoPo customerRelationInfoPo = new CustomerRelationInfoPo();
                    customerRelationInfoPo.setSubSystemSign("JWBX");
                    customerRelationInfoPo.setSystemSign("BX");
                    customerRelationInfoPo.setRelationId("tbJWBX" + customerProductInfoRo.getCustomerNo() + "bbJWBX" + jwbxCusTomerPO1.getCustomerNo());
                    customerRelationInfoPo.setCustomerNo(customerProductInfoRo.getCustomerNo());
                    customerRelationInfoPo.setRoleInRelation(2);
                    CustomerRelationInfoPo customerRelationInfoPo1 = null;
                    try {
                        customerRelationInfoPo1 = customerRelationInfoMapper.selectOne(customerRelationInfoPo);
                    } catch (Exception e) {

                    }
                    if (customerRelationInfoPo1 == null) {
                        customerRelationInfoPo.setId(UUIDUtils.getUUID());
                        customerRelationInfoPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
                        customerRelationInfoPo.setSubSystemSign("JWBX");
                        customerRelationInfoPo.setSystemSign("BX");
                        customerRelationInfoPo.setRelationId("tbJWBX" + customerProductInfoRo.getCustomerNo() + "bbJWBX" + jwbxCusTomerPO1.getCustomerNo());
                        customerRelationInfoPo.setRelationSource(2);
                        customerRelationInfoPo.setRoleInRelation(2);
                        customerRelationInfoMapper.insert(customerRelationInfoPo);
                    }
                    customerRelationInfoPo.setRoleInRelation(3);
                    customerRelationInfoPo.setCustomerNo(jwbxCusTomerPO1.getCustomerNo());
                    CustomerRelationInfoPo customerRelationInfoPo2 = customerRelationInfoMapper.selectOne(customerRelationInfoPo);
                    if (customerRelationInfoPo2 == null) {
                        customerRelationInfoPo.setId(UUIDUtils.getUUID());
                        customerRelationInfoPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
                        customerRelationInfoPo.setSubSystemSign("JWBX");
                        customerRelationInfoPo.setSystemSign("BX");
                        customerRelationInfoPo.setRelationId("tbJWBX" + customerProductInfoRo.getCustomerNo() + "bbJWBX" + jwbxCusTomerPO1.getCustomerNo());
                        customerRelationInfoPo.setRelationSource(2);
                        customerRelationInfoPo.setRoleInRelation(3);
                        customerRelationInfoMapper.insert(customerRelationInfoPo);
                    }

                }
            }
        }
    }

    @Override
    public void bulidHHRCJOrder(BinlogRo binlogRo) {

        CustomerProductInfoRo customerProductInfoRo = new CustomerProductInfoRo();
        customerProductInfoRo.setDatabaseName(binlogRo.getSchemaName());
        customerProductInfoRo.setTableName(binlogRo.getTableName());
        String eventType = binlogRo.getEventType();
        customerProductInfoRo.setSyncType(eventType);
        List<BinlogColumnRo> afterColumns = binlogRo.getRows().getAfterColumns();
        List<BinlogColumnRo> beforeColumns = binlogRo.getRows().getBeforeColumns();
        if (SyncTypeEnum.DELETE.getValue().equals(eventType)){
            inithhrcjCustomerProductInfoRo(beforeColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.UPDATE.getValue().equals(eventType)){
            inithhrcjCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }
        if (SyncTypeEnum.NEW.getValue().equals(eventType)){
            inithhrcjCustomerProductInfoRo(afterColumns,customerProductInfoRo);
        }
    }
    private void inithhrcjCustomerProductInfoRo(List<BinlogColumnRo> beforeColumns, CustomerProductInfoRo customerProductInfoRo) {
        customerProductInfoRo.setSubSystemSign("HHR_CF");
        customerProductInfoRo.setSystemSign("HHR");
        customerProductInfoRo.setProductSourceSystem(1+"");
        for (BinlogColumnRo c:beforeColumns) {
            String name = c.getName();
            Object value = c.getValue();
            try {

                if ("invest_amt".equals(name)){
                    customerProductInfoRo.setProductAmount(new BigDecimal((String) value));
                }
                if ("p_id".equals(name)){
                    customerProductInfoRo.setProductNo((String) value);
                    Example example = new Example(HHRCFProductPO.class);
                    Example.Criteria criteria = example.createCriteria();
                    criteria.andEqualTo("p_id",name);
                    HHRCFProductPO hhrcfProductPO = null;
                    try {
                        hhrcfProductPO = hhrcfProductMapper.selectOneByExample(example);
                    } catch (Exception e) {
                    }
                    if (hhrcfProductPO!=null) {
                        customerProductInfoRo.setProductDeadline(hhrcfProductPO.getP_periods() * 30 + "");
                    }

                }
                if ("l_record_interest_time".equals(name)){
                    customerProductInfoRo.setProductStartTime(CustomerUtils.dateStr2Timestamp((String) value));
                }
                if ("expire_time".equals(name)){
                    customerProductInfoRo.setProductEndTime(CustomerUtils.dateStr2Timestamp((String) value));
                }
                if ("id".equals(name)){
                    customerProductInfoRo.setTableKey((String) value);
                }
                if ("l_status".equals(name)){
                    customerProductInfoRo.setProductStatus(getYZTStatus("HHR_CF"+(String) value));
                }
                if ("u_id".equals(name)){
                    customerProductInfoRo.setUserResourceId((String) value);
                    Example example = new Example(HHRCFAccountPO.class);
                    Example.Criteria criteria = example.createCriteria();
                    criteria.andEqualTo("u_id",name);
                    HHRCFAccountPO hhrcfAccountPO = null;
                    try {
                        hhrcfAccountPO = hhrcfAccountMapper.selectOneByExample(example);
                    } catch (Exception e) {
                        //
                    }
                    if (hhrcfAccountPO!=null) {
                        customerProductInfoRo.setCustomerNo(hhrcfAccountPO.getCustomerNo());
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("------------------------"+name+"数据类型转换失败--------------------");
            }
        }
        if (StringUtils.isNotBlank(customerProductInfoRo.getCustomerNo())) {
            syncDataService.syncCustomerProduct(customerProductInfoRo);
        }
    }

    private void initCHDCustomerProductInfoRo(Map<String, String> map, CustomerProductInfoRo customerProductInfoRo) {
        customerProductInfoRo.setSystemSign("CHD");
        customerProductInfoRo.setSubSystemSign("CHD");
        customerProductInfoRo.setProductSourceSystem("17");
        customerProductInfoRo.setProductStatus(getYZTStatus("CHD"+map.get("busi_status")));
        customerProductInfoRo.setTableKey(map.get("id"));
        customerProductInfoRo.setProductNo(map.get("prod_plan"));
        Example l = new Example(CHDLesseePO.class);
        Example.Criteria lc = l.createCriteria();
        lc.andEqualTo("businessId",map.get("id"));
        CHDLesseePO chdLesseePO = null;
        try {
            chdLesseePO = lesseeMapper.selectOneByExample(l);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (chdLesseePO !=null && StringUtils.isNotBlank(chdLesseePO.getCustomerNo())){
            customerProductInfoRo.setCustomerNo(chdLesseePO.getCustomerNo());
            customerProductInfoRo.setUserResourceId("CHD"+ chdLesseePO.getCustomerNo());

            Example example =  new Example(CHDContractLoanPO.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("contractCode",map.get("contract_code"));
            CHDContractLoanPO chdContractLoanPO = null;
            try {
                chdContractLoanPO = contractLoanMapper.selectOneByExample(example);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (chdContractLoanPO !=null) {
                customerProductInfoRo.setProductAmount(chdContractLoanPO.getLoanMoney());
                if (chdContractLoanPO.getLoanDate() != null) {
                    customerProductInfoRo.setProductStartTime(new Timestamp(chdContractLoanPO.getLoanDate()));
                }
            }
            Example example1 = new Example(CHDContractPO.class);
            Example.Criteria criteria1 = example1.createCriteria();
            criteria1.andEqualTo("contractCode",map.get("contract_code"));
            CHDContractPO chdContractPO = null;
            try {
                chdContractPO = contractMapper.selectOneByExample(example1);
            } catch (Exception e) {
                //e.printStackTrace();
            }
            if (chdContractPO != null  && chdContractPO.getEndDate()!= null){
                customerProductInfoRo.setProductEndTime(new Timestamp(chdContractPO.getEndDate()));
            }

            Example example2 = new Example(CHDEntryBasicInfoPO.class);
            Example.Criteria criteria2 = example2.createCriteria();
            criteria2.andEqualTo("businessId",map.get("id"));
            CHDEntryBasicInfoPO chdEntryBasicInfoPO = entryBasicInfoMapper.selectOneByExample(example2);
            if (chdEntryBasicInfoPO !=null){
                Example example3 = new Example(CHDEntryProdInfoPO.class);
                Example.Criteria criteria3 = example3.createCriteria();
                criteria3.andEqualTo("entryId", chdEntryBasicInfoPO.getId());
                criteria3.andEqualTo("prodPlanfrom","C");
                CHDEntryProdInfoPO chdEntryProdInfoPO = entryProdInfoMapper.selectOneByExample(example3);
                if (chdEntryProdInfoPO != null && chdEntryProdInfoPO.getLessee_time()!=null ){
                    customerProductInfoRo.setProductDeadline(chdEntryProdInfoPO.getLessee_time()*30+"");
                }
            }
            //if (StringUtils.isNotBlank(customerProductInfoRo.getProductNo())){
            syncDataService.syncCustomerProduct(customerProductInfoRo);
            //}
        }
    }

    private void initBDBCustomerProduct(CustomerProductInfoRo customerProductInfoRo, Map<String, String> map) {

        customerProductInfoRo.setSyncType(SyncTypeEnum.NEW.getValue());
        customerProductInfoRo.setSystemSign("BX");
        customerProductInfoRo.setSubSystemSign("BDB");
        customerProductInfoRo.setProductStatus(6);
        customerProductInfoRo.setProductSourceSystem("19");
        customerProductInfoRo.setProductStartTime(CustomerUtils.dateStr2Timestamp(map.get("startdate")));
        customerProductInfoRo.setProductEndTime(CustomerUtils.dateStr2Timestamp(map.get("enddate")));
        if (customerProductInfoRo.getProductStartTime()!=null && customerProductInfoRo.getProductEndTime() != null){
            int deadLine = (int) ((customerProductInfoRo.getProductEndTime().getTime() - customerProductInfoRo.getProductStartTime().getTime()) / (1000 * 3600 * 24));
            customerProductInfoRo.setProductDeadline(deadLine + "");
        }
        customerProductInfoRo.setTableKey(map.get("id"));
        String order_no = map.get("order_no");
        Example orderToCustomE = new Example(HrhbOrderToCustomPO.class);
        Example.Criteria orderToCustomCriteria = orderToCustomE.createCriteria();
        orderToCustomCriteria.andEqualTo("orderno",order_no);
        List<HrhbOrderToCustomPO> hrhbOrderToCustomPOS = hrhbOrderToCustomMapper.selectByExample(orderToCustomE);
        for (HrhbOrderToCustomPO h:hrhbOrderToCustomPOS) {
            Example hrhbCustomE = new Example(HhrbCustomPO.class);
            Example.Criteria hrhbCustomC = hrhbCustomE.createCriteria();
            hrhbCustomC.andEqualTo("customcode",h.getCustomcode());
            HhrbCustomPO hhrbCustomPO = hhrbCustomMapper.selectOneByExample(hrhbCustomE);
            if (hhrbCustomPO!= null) {
                Example yztCustomE = new Example(YztCustomPO.class);
                Example.Criteria yztCustomC = yztCustomE.createCriteria();
                yztCustomC.andEqualTo("idno", hhrbCustomPO.getIdno());
                YztCustomPO yztCustomPO = yztCustomMapper.selectOneByExample(yztCustomE);
                if (yztCustomPO!=null && StringUtils.isNotBlank(yztCustomPO.getCustomNo())) {
                    h.setCustomNo(yztCustomPO.getCustomNo());
                }
            }
        }

        Example subOrderE = new Example(HrhbSubOrderPO.class);
        Example.Criteria subOrderC = subOrderE.createCriteria();
        subOrderC.andEqualTo("orderno",order_no);
        List<HrhbSubOrderPO> hrhbSubOrderPOS = hrhbSubOrderMapper.selectByExample(subOrderE);
        List<HrhbOrderToCustomPO> tb = new ArrayList<>();
        List<HrhbOrderToCustomPO> bb = new ArrayList<>();
        for (HrhbSubOrderPO h:hrhbSubOrderPOS) {
            for (HrhbOrderToCustomPO o:hrhbOrderToCustomPOS) {
                if ("01".equals(o.getRelationtype())){
                    customerProductInfoRo.setCustomerRole("3");
                    customerProductInfoRo.setUserResourceId(o.getCustomcode());
                    customerProductInfoRo.setCustomerNo(o.getCustomNo());
                    customerProductInfoRo.setProductAmount(new BigDecimal(h.getFee()));
                    customerProductInfoRo.setProductNo(h.getProductcode());
                    if (StringUtils.isNotBlank(customerProductInfoRo.getCustomerNo())) {
                        customerProductInfoRo.setTableKey("s"+map.get("id")+"o"+h.getId()+"c"+o.getId());
                        syncDataService.syncCustomerProduct(customerProductInfoRo);
                        tb.add(o);
                    }

                }else if ("02".equals(o.getRelationtype())){
                    //增加被保人角色
                    if (StringUtils.isNotBlank(o.getCustomNo())) {
                        syncDataService.addRoleInfo(o.getCustomcode(),o.getCustomNo(),"BX","BDB","4",CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
                        bb.add(o);
                    }

                }
              /*  if ("01".equals(o.getRelationtype()) || "02".equals(o.getRelationtype())) {
                    customerProductInfoRo.setCustomerRole("01".equals(o.getRelationtype()) ?"3":"4");
                    customerProductInfoRo.setUserResourceId(o.getCustomcode());
                    customerProductInfoRo.setCustomerNo(o.getCustomNo());
                    customerProductInfoRo.setProductAmount(new BigDecimal(h.getFee()));
                    customerProductInfoRo.setProductNo(h.getProductcode());
                    if (StringUtils.isNotBlank(customerProductInfoRo.getCustomerNo())) {
                        customerProductInfoRo.setTableKey("s"+map.get("id")+"o"+h.getId()+"c"+o.getId());
                        syncDataService.syncCustomerProduct(customerProductInfoRo);
                        if ("01".equals(o.getRelationtype())){
                            tb.add(o);
                        }else {
                            bb.add(o);
                        }
                    }
                }*/
            }
        }
        //添加关系
        for (HrhbOrderToCustomPO tbr: tb) {
            for (HrhbOrderToCustomPO bbr:bb) {
                CustomerRelationInfoPo customerRelationInfoPo = new CustomerRelationInfoPo();
                customerRelationInfoPo.setRelationId("tb"+tbr.getCustomcode()+"bb"+bbr.getCustomcode());
                customerRelationInfoPo.setCustomerNo(tbr.getCustomNo());
                customerRelationInfoPo.setRoleInRelation(2);
                CustomerRelationInfoPo customerRelationInfoPo1 = customerRelationInfoMapper.selectOne(customerRelationInfoPo);
                if (customerRelationInfoPo1 == null) {
                    customerRelationInfoPo.setId(UUIDUtils.getUUID());
                    customerRelationInfoPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
                    customerRelationInfoPo.setSubSystemSign("BDB");
                    customerRelationInfoPo.setSystemSign("BX");
                    customerRelationInfoPo.setRelationId("tb"+tbr.getCustomcode()+"bb"+bbr.getCustomcode());
                    customerRelationInfoPo.setRelationSource(2);
                    customerRelationInfoPo.setRoleInRelation(2);
                    customerRelationInfoMapper.insert(customerRelationInfoPo);
                }
                customerRelationInfoPo.setRoleInRelation(3);
                customerRelationInfoPo.setCustomerNo(bbr.getCustomNo());
                CustomerRelationInfoPo customerRelationInfoPo2 = customerRelationInfoMapper.selectOne(customerRelationInfoPo);
                if (customerRelationInfoPo2 == null) {
                    customerRelationInfoPo.setId(UUIDUtils.getUUID());
                    customerRelationInfoPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
                    customerRelationInfoPo.setSubSystemSign("BDB");
                    customerRelationInfoPo.setSystemSign("BX");
                    customerRelationInfoPo.setRelationId("tb"+tbr.getCustomcode()+"bb"+bbr.getCustomcode());
                    customerRelationInfoPo.setRelationSource(2);
                    customerRelationInfoPo.setRoleInRelation(3);
                    customerRelationInfoMapper.insert(customerRelationInfoPo);
                }
            }
        }
    }

    private void initNewCustomerProduct(CustomerProductInfoRo customerProductInfoRo, Map<String, String> afterMap) {
        customerProductInfoRo.setUserResourceId("个贷表里没有用户id");
        String intoprecesId =  afterMap.get("ip_id");
        customerProductInfoRo.setTableKey(intoprecesId);
        if (StringUtils.isNotBlank(intoprecesId)) {
            CrmIntopiecesDkPO crmIntopiecesDkPO = crmIntopiecesDkMapper.selectByPrimaryKey(intoprecesId);
            if (crmIntopiecesDkPO != null) {
                customerProductInfoRo.setProductNo(crmIntopiecesDkPO.getLoanType());
                Example example = new Example(CrmAccountMesDkPO.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("intopiecesId", intoprecesId);
                CrmAccountMesDkPO crmAccountMesDkPO = crmAccountMesDkMapper.selectOneByExample(example);
                CrmRepayDkPO crmRepayDkPO = null;
                Integer accountType = null;
                Integer isTrust = null;
                Integer isNewPlatform = null;
                Integer state = crmIntopiecesDkPO.getState();
                Integer status = null;
                Integer sys = crmIntopiecesDkPO.getPiecesType();
                if (crmAccountMesDkPO != null) {
                    accountType = crmAccountMesDkPO.getAccountType();
                    isTrust = crmAccountMesDkPO.getIsTrust();
                    isNewPlatform = crmAccountMesDkPO.getIsNewPlatform();
                    Example example1 = new Example(CrmRepayDkPO.class);
                    Example.Criteria criteria1 = example1.createCriteria();
                    criteria1.andEqualTo("contractId", crmAccountMesDkPO.getId());
                    crmRepayDkPO = crmRepayDkMapper.selectOneByExample(example1);

                    if (crmRepayDkPO != null) {
                        status = crmRepayDkPO.getStatus();
                    }

                    customerProductInfoRo.setProductNo(crmIntopiecesDkPO.getLoanType());


                    //customerProductInfoRo.setProductSourceSystem(CustomerConstants.GD + "");
                    customerProductInfoRo.setProductAmount(crmIntopiecesDkPO.getCount());
                    if (crmAccountMesDkPO != null) {
                        customerProductInfoRo.setProductDeadline(crmAccountMesDkPO.getLoan_qishu() * 30 + "");
                        customerProductInfoRo.setProductEndTime(new Timestamp(crmAccountMesDkPO.getRepayEndTime()*1000));
                        customerProductInfoRo.setProductStartTime(new Timestamp(crmAccountMesDkPO.getRepayStartTime()*1000));
                        customerProductInfoRo.setProductAmount(crmAccountMesDkPO.getAccountMoney());
                    }
                }
                bulidGDProductStatus(customerProductInfoRo, state, status);
                bulidGdSystemSign(sys, customerProductInfoRo, accountType, isTrust, isNewPlatform);
                customerProductInfoRo.setPreCustomerNo(afterMap.get("client_id"));
                customerProductInfoRo.setCustomerNo(afterMap.get("knnent_id"));
                customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
                customerProductInfoRo.setCustomerRole(CustomerConstants.CUSTOMER_ACCOUNT_TYPE_LOAN);
            }
        }
    }

    private void initGdCustomerProduct(CustomerProductInfoRo customerProductInfoRo, Map<String, String> afterMap) {
        customerProductInfoRo.setUserResourceId("个贷表里没有用户id");
        String id = afterMap.get(TableNameConstants.GD_JJ_ID);
        customerProductInfoRo.setTableKey(id);
        Example example2 = new Example((CrmIntopiecesInfoDkPO.class));
        Example.Criteria criteria2 = example2.createCriteria();
        criteria2.andEqualTo("intopiecesId",id);
        CrmIntopiecesInfoDkPO crmClientYztPO = crmClientYztMapper.selectOneByExample(example2);
        Example example = new Example(CrmAccountMesDkPO.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("intopiecesId",id);
        CrmAccountMesDkPO crmAccountMesDkPO = crmAccountMesDkMapper.selectOneByExample(example);
        CrmRepayDkPO crmRepayDkPO = null;
        Integer accountType = null;
        Integer isTrust = null;
        Integer isNewPlatform = null;
        if (crmAccountMesDkPO != null) {
            accountType = crmAccountMesDkPO.getAccountType();
            isTrust = crmAccountMesDkPO.getIsTrust();
            isNewPlatform = crmAccountMesDkPO.getIsNewPlatform();
            Example example1 = new Example(CrmRepayDkPO.class);
            Example.Criteria criteria1 = example1.createCriteria();
            criteria1.andEqualTo("contractId", crmAccountMesDkPO.getId());
            try {
                crmRepayDkPO = crmRepayDkMapper.selectOneByExample(example1);
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }

        Integer status = null;
        if (crmRepayDkPO != null){
           status = crmRepayDkPO.getStatus();
        }
        Integer state = Integer.valueOf(afterMap.get("state"));
        customerProductInfoRo.setProductNo(afterMap.get("loan_type"));
        bulidGDProductStatus(customerProductInfoRo,state,status);
        Integer sys = Integer.valueOf(afterMap.get(TableNameConstants.GD_JJ_SYSTEM));
        bulidGdSystemSign(sys,customerProductInfoRo,accountType,isTrust,isNewPlatform);
       // customerProductInfoRo.setProductSourceSystem(CustomerConstants.GD+"");
        customerProductInfoRo.setProductAmount(new BigDecimal(afterMap.get(TableNameConstants.GD_JJ_COUNT)));
        if (crmAccountMesDkPO != null) {
            try {
                customerProductInfoRo.setProductDeadline(crmAccountMesDkPO.getLoan_qishu()*30+"");
            } catch (NumberFormatException e) {
            }
            System.out.println("");
            customerProductInfoRo.setProductEndTime(new Timestamp(crmAccountMesDkPO.getRepayEndTime()*1000));
            customerProductInfoRo.setProductStartTime(new Timestamp(crmAccountMesDkPO.getRepayStartTime()*1000));
            customerProductInfoRo.setProductAmount(crmAccountMesDkPO.getAccountMoney());
        }

        if (crmClientYztPO!=null) {
            customerProductInfoRo.setPreCustomerNo(crmClientYztPO.getClientId());
            customerProductInfoRo.setCustomerNo(crmClientYztPO.getKnnentId());
        }
        customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
        customerProductInfoRo.setCustomerRole(CustomerConstants.CUSTOMER_ACCOUNT_TYPE_LOAN);

    }

    private void bulidGDProductStatus(CustomerProductInfoRo customerProductInfoRo, Integer state, Integer status) {
        Integer yztStatus = null;
        if (state == 12){
            yztStatus = getYZTStatus("GD"+state+status);
        }else{
            yztStatus = getYZTStatus("GD"+state);
        }
        customerProductInfoRo.setProductStatus(yztStatus);
    }

    public static void bulidGdSystemSign(Integer sys, CustomerProductInfoRo customerProductInfoRo,Integer accountType,Integer isTrust, Integer isNewPlatform) {
        if (accountType !=null){

            if (accountType ==1){
                customerProductInfoRo.setSystemSign("HHR");
                customerProductInfoRo.setSubSystemSign("HHR_JK");
                customerProductInfoRo.setProductSourceSystem("1");
            }else if (accountType == 2){
                if (isNewPlatform == 1){
                    customerProductInfoRo.setSystemSign("DLR");
                    customerProductInfoRo.setSubSystemSign("DLR");
                    customerProductInfoRo.setProductSourceSystem("2");
                }else if (isNewPlatform ==0 ){
                    customerProductInfoRo.setSystemSign("HYR");
                    customerProductInfoRo.setSubSystemSign("HYR");
                    customerProductInfoRo.setProductSourceSystem("3");
                }
            }else if (accountType == 3){
                customerProductInfoRo.setSystemSign("XXHT");
                customerProductInfoRo.setSubSystemSign("XXHT");
                customerProductInfoRo.setProductSourceSystem("12");
            }else if (accountType == 4){
                customerProductInfoRo.setSystemSign("SB");
                customerProductInfoRo.setSubSystemSign("SB");
                customerProductInfoRo.setProductSourceSystem("12");
            }else if (accountType == 5){
                customerProductInfoRo.setSystemSign("XT");
                customerProductInfoRo.setSubSystemSign("XT");
                customerProductInfoRo.setProductSourceSystem("16");
                if (isTrust ==0){
                    customerProductInfoRo.setSubSystemSign("WMXT");
                    customerProductInfoRo.setProductSourceSystem("7");
                }else if (isTrust == 1){
                    customerProductInfoRo.setSubSystemSign("WMXT");
                    customerProductInfoRo.setProductSourceSystem("7");
                }else if (isTrust == 2){
                    customerProductInfoRo.setSubSystemSign("HAXT");
                    customerProductInfoRo.setProductSourceSystem("5");
                }else if (isTrust == 4){
                    customerProductInfoRo.setSubSystemSign("BHXT");
                    customerProductInfoRo.setProductSourceSystem("6");
                }
            }else if (accountType == 6){
                customerProductInfoRo.setSystemSign("XD");
                customerProductInfoRo.setSubSystemSign("CCXD");
                customerProductInfoRo.setProductSourceSystem("15");
            }else if (accountType == 8){
                customerProductInfoRo.setSystemSign("XD");
                customerProductInfoRo.setSubSystemSign("BJXD");
                customerProductInfoRo.setProductSourceSystem("14");
            }else if (accountType == 9){
                customerProductInfoRo.setSystemSign("CD");
                customerProductInfoRo.setSubSystemSign("CD");
                customerProductInfoRo.setProductSourceSystem("17");

            }else if (accountType == 10){
                customerProductInfoRo.setSystemSign("XD");
                customerProductInfoRo.setSubSystemSign("BJXD");
                customerProductInfoRo.setProductSourceSystem("14");
            }else if (accountType == 11){
                customerProductInfoRo.setSystemSign("XD");
                customerProductInfoRo.setSubSystemSign("CCXD");
                customerProductInfoRo.setProductSourceSystem("15");
            }
        }else{

            if (sys == 1){
                customerProductInfoRo.setSubSystemSign("PHGD");
                customerProductInfoRo.setSystemSign("PHGD");
                customerProductInfoRo.setProductSourceSystem("12");
            }else if (sys == 2){
                customerProductInfoRo.setSystemSign("XT");
                customerProductInfoRo.setSubSystemSign("XT");
                customerProductInfoRo.setProductSourceSystem("16");
            }else if (sys == 3){
                customerProductInfoRo.setSystemSign("XD");
                customerProductInfoRo.setSubSystemSign("CCXD");
                customerProductInfoRo.setProductSourceSystem("15");
            }else if (sys == 4){
                customerProductInfoRo.setSystemSign("XD");
                customerProductInfoRo.setSubSystemSign("BJXD");
                customerProductInfoRo.setProductSourceSystem("14");
            }else if (sys ==5){
                customerProductInfoRo.setSystemSign("CD");
                customerProductInfoRo.setSubSystemSign("CD");
                customerProductInfoRo.setProductSourceSystem("17");
            }

        }
    }

    private void initXhqbCustomerProductInfoRo(List<BinlogColumnRo> columns, CustomerProductInfoRo customerProductInfoRo) {
        customerProductInfoRo.setSubSystemSign(CustomerConstants.XHQB);
        customerProductInfoRo.setSystemSign(CustomerConstants.XHQB);
        customerProductInfoRo.setProductSourceSystem(CustomerConstants.XHQB_CODE+"");
        customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
        customerProductInfoRo.setProductNo(TableNameConstants.XHQB_JYFQ_CODE);
        for (BinlogColumnRo c:columns) {
            String name = c.getName();
            Object value = c.getValue();
            try {

                if (TableNameConstants.XHQB_ORDER_MONEY.equals(name)){
                    customerProductInfoRo.setProductAmount(new BigDecimal(Integer.valueOf((String) value)/100));
                }

                if (TableNameConstants.XHQB_ORDER_START_TIME.equals(name)){

                    customerProductInfoRo.setProductStartTime(CustomerUtils.dateStr2Timestamp((String) value));
                }
                if ("course_rate_id".equals(name)){
                    XhqbDateLine xhqbDateLine = xhqbOrderMapper.queryDeadLine((String) value);
                    if (xhqbDateLine != null){
                        if (xhqbDateLine.getRepayment_type() == 2){
                            customerProductInfoRo.setProductDeadline((xhqbDateLine.getEarlier_periods()+xhqbDateLine.getLater_periods())*30+"");
                        }else{
                            customerProductInfoRo.setProductDeadline(xhqbDateLine.getPeriods()*30+"");
                        }
                    }

                }
                if (TableNameConstants.XHQB_ORDER_STS.equals(name)){
                    customerProductInfoRo.setProductStatus(getYZTStatus(CustomerConstants.XHQB+(String) value));
                }
                if (TableNameConstants.XHQB_LEND_TABLE_KEY.equals(name)){
                    customerProductInfoRo.setTableKey((String) value);
                }
                if (TableNameConstants.XHQB_ORDER_USER_ID.equals(name)){

                    customerProductInfoRo.setUserResourceId((String) value);
                    CustomerNoPo byUserId = xhqb2Mapper.getByUserId((String) value);
                    if (byUserId !=null){
                        customerProductInfoRo.setCustomerNo(byUserId.getCustomerNo());
                        customerProductInfoRo.setPreCustomerNo(byUserId.getPreCustomerNo());

                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("------------------------"+name+"数据类型转换失败--------------------");
            }
        }
    }

    private void initHydCustomerProductInfoRo(List<BinlogColumnRo> columns, CustomerProductInfoRo customerProductInfoRo) {
        customerProductInfoRo.setSubSystemSign(CustomerConstants.HYD);
        customerProductInfoRo.setSystemSign(CustomerConstants.HYD);
        customerProductInfoRo.setProductSourceSystem(CustomerConstants.HYR_CODE+"");
        customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
        customerProductInfoRo.setCustomerRole(CustomerConstants.CUSTOMER_ACCOUNT_TYPE_LOAN);
        for (BinlogColumnRo c:columns) {
            String name = c.getName();
            Object value = c.getValue();
            try {

                if (TableNameConstants.HYD_ORDER_MONEY.equals(name)){
                    if (StringUtils.isNotBlank((String) value)) {
                        customerProductInfoRo.setProductAmount(new BigDecimal((String) value));
                    }
                }
                if (TableNameConstants.HYD_ORDER_PRODUCT_NO.equals(name)){
                    customerProductInfoRo.setProductNo((String) value);
                }
                if (TableNameConstants.HYD_ORDER_START_TIME.equals(name)){

                    customerProductInfoRo.setProductStartTime(CustomerUtils.dateStr2Timestamp((String) value));
                }
                if (TableNameConstants.HYD_ORDER_END_TIME.equals(name)){

                    try {
                        customerProductInfoRo.setProductEndTime(CustomerUtils.dateStr2Timestamp((String) value));
                    } catch (Exception e) {

                    }
                }
                if (TableNameConstants.HYD_ORDER_DEADLINE.equals(name)){
                    try {
                        customerProductInfoRo.setProductDeadline(Integer.valueOf( (String) value) *30+"");
                    } catch (NumberFormatException e) {
                       // e.printStackTrace();
                    }
                }
                if (TableNameConstants.HYD_ORDER_STS.equals(name)){
                    customerProductInfoRo.setProductStatus(getYZTStatus(CustomerConstants.HYD+(String) value));
                }
                if (TableNameConstants.HYD_LEND_TABLE_KEY.equals(name)){
                    customerProductInfoRo.setTableKey((String) value);
                }
                if (TableNameConstants.HYD_ORDER_USER_ID.equals(name)){
                    customerProductInfoRo.setUserResourceId((String) value);
                    CustomerNoPo byUserId = hydMapper.getByUserId((String) value);
                    if (byUserId !=null){
                        customerProductInfoRo.setCustomerNo(byUserId.getCustomerNo());
                        customerProductInfoRo.setPreCustomerNo(byUserId.getPreCustomerNo());
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("------------------------"+name+"数据类型转换失败--------------------");
            }
        }
    }
    private void initHyrFixCustomerProductInfoRo(List<BinlogColumnRo> columns, CustomerProductInfoRo customerProductInfoRo) {
        String dtbtype = "";
        String crmid = "";
        String status = "";
        String id = "";
        for (BinlogColumnRo c:columns) {
            String name = c.getName();
            Object value = c.getValue();
            try {
                if ("dtbtype".equals(name)){
                    dtbtype = (String) value;
                }else if ("crmid".equals(name)){
                    crmid = (String) value;
                }else if ("status".equals(name)){
                    status = (String) value;
                }else if ("id".equals(name)){
                    id = (String) value;
                }else if ("crmlc_times".equals(name)){
                    if(!"1".equals((String) value)){
                        return;
                    };
                }

            } catch (Exception e) {
                e.printStackTrace();
                log.error("------------------------" + name + "数据类型转换失败--------------------");
            }
        }
        SystemLendPo hyrOrderPo = null;
        if ("1".equals(dtbtype)&& StringUtils.isNotBlank(crmid)){
            hyrOrderPo = hyrMapper.selectfixCP(crmid);
        }else if ("2".equals(dtbtype)&& StringUtils.isNotBlank(crmid)){
            hyrOrderPo = hyrMapper.selectThrowCP(crmid);
        }else if ("4".equals(dtbtype)&& StringUtils.isNotBlank(crmid)){
            hyrOrderPo = hyrMapper.selectOrderCP(crmid);
        }
        if (hyrOrderPo!=null) {
            customerProductInfoRo.setSubSystemSign(CustomerConstants.HYR);
            customerProductInfoRo.setSystemSign(CustomerConstants.HYR);
            customerProductInfoRo.setTableKey(id);
            customerProductInfoRo.setProductSourceSystem(CustomerConstants.HYR_CODE+"");
            customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
            customerProductInfoRo.setProductAmount(hyrOrderPo.getAmount());
            customerProductInfoRo.setProductNo(hyrOrderPo.getProductId());
            customerProductInfoRo.setProductStartTime(hyrOrderPo.getCapitalEffectDate());
            customerProductInfoRo.setProductEndTime(hyrOrderPo.getExpireDate());
            customerProductInfoRo.setProductDeadline(hyrOrderPo.getPeriod()*30+"");
            customerProductInfoRo.setUserResourceId(hyrOrderPo.getUserId());
            CustomerNoPo byUserId = hyrMapper.getByUserId(hyrOrderPo.getUserId());
            if (byUserId !=null){
                customerProductInfoRo.setCustomerNo(byUserId.getCustomerNo());
                customerProductInfoRo.setPreCustomerNo(byUserId.getPreCustomerNo());

            }
            customerProductInfoRo.setProductStatus(getYZTStatus(CustomerConstants.HYR+status));

        }
    }
    private void initDlrCustomerProductInfoRo(List<BinlogColumnRo> columns, CustomerProductInfoRo customerProductInfoRo) {
        customerProductInfoRo.setSubSystemSign(CustomerConstants.DLR);
        customerProductInfoRo.setSystemSign(CustomerConstants.DLR);
        customerProductInfoRo.setProductSourceSystem(CustomerConstants.DLR_CODE+"");
        customerProductInfoRo.setCustomerRoleStatus(CustomerConstants.CUSTOMER_ROLE_EFFECTIVE);
        for (BinlogColumnRo c:columns) {
            String name = c.getName();
            Object value = c.getValue();
            try {

                if (TableNameConstants.DLR_QM_LEND_ORDER_AMOUNT.equals(name)){
                    customerProductInfoRo.setProductAmount(new BigDecimal((String) value));
                }
                if (TableNameConstants.DLR_QM_LEND_ORDER_SUB_PRODUCT_CODE.equals(name)){
                    customerProductInfoRo.setProductNo((String) value);
                }
                if (TableNameConstants.DLR_QM_LEND_ORDER_CAPITAL_EFFECT_DATE.equals(name)){

                    customerProductInfoRo.setProductStartTime(CustomerUtils.dateStr2Timestamp((String) value));
                }
                if (TableNameConstants.DLR_QM_LEND_ORDER_EXPIRE_DATE.equals(name)){
                    customerProductInfoRo.setProductEndTime(CustomerUtils.dateStr2Timestamp((String) value));
                }
                if (TableNameConstants.DLR_QM_LEND_ORDER_PERIOD.equals(name)){
                    customerProductInfoRo.setProductDeadline((String) value);
                }
                if (TableNameConstants.DLR_LEND_TABLE_KEY.equals(name)){
                    customerProductInfoRo.setTableKey((String) value);
                }
                if (TableNameConstants.DLR_QM_LEND_ORDER_STS.equals(name)){
                    customerProductInfoRo.setProductStatus(getYZTStatus(CustomerConstants.DLR+(String) value));
                }
                if (TableNameConstants.DLR_QM_LEND_ORDER_USER_ID.equals(name)){

                    customerProductInfoRo.setUserResourceId((String) value);
                    log.info("开始查表 订单##########################################");
                    CustomerNoPo byUserId = null;
                    try {
                        byUserId = dlrMapper.getByUserId((String) value);
                    } catch (Exception e) {
                        log.error(e.getMessage());
                    }
                    if (byUserId !=null){
                        customerProductInfoRo.setCustomerNo(byUserId.getCustomerNo());
                        customerProductInfoRo.setPreCustomerNo(byUserId.getPreCustomerNo());
                        /*if (byUserId.getCustomerNo()!=null){
                            customerProductInfoRo.setCustomerRole(getCustomerRole(byUserId.getCustomerNo(),CustomerConstants.DLR,CustomerConstants.DLR));
                        }else{
                            customerProductInfoRo.setCustomerRole(getCustomerRole(byUserId.getPreCustomerNo(),CustomerConstants.DLR,CustomerConstants.DLR));
                        }*/
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("------------------------"+name+"数据类型转换失败--------------------");
            }
        }
    }

    public static Integer getYZTStatus(String value) {
        Map<String ,Integer> map = new HashMap<>();
        map.put("DLR6",2);
        map.put("DLR3",6);
        map.put("DLR8",6);
        map.put("DLR9",6);
        map.put("DLR5",7);
        map.put("DLR0",8);
        map.put("DLR1",8);
        map.put("DLR2",8);

        map.put("HYR1",8);
        map.put("HYR2",7);
        map.put("HYR3",6);
        map.put("HYR4",6);
        map.put("HYR5",6);
        map.put("HYR6",8);
        map.put("HYR7",6);
        map.put("HYR0",8);



        map.put("HYD10105",1);
        map.put("HYD10110",1);
        map.put("HYD10130",1);
        map.put("HYD10131",1);
        map.put("HYD10141",1);
        map.put("HYD10107",2);
        map.put("HYD10108",2);
        map.put("HYD10109",2);
        map.put("HYD10120",2);
        map.put("HYD10140",2);
        map.put("HYD10151",2);
        map.put("HYD10200",2);
        map.put("HYD10106",2);
        map.put("HYD10160",2);
        map.put("HYD10161",2);
        map.put("HYD10260",2);
        map.put("HYD10210",3);
        map.put("HYD10211",3);
        map.put("HYD10220",4);
        map.put("HYD10230",5);
        map.put("HYD10240",5);
        map.put("HYD10152",8);
        map.put("HYD10190",8);
        map.put("HYD10250",8);
        map.put("HYD10150",8);
        map.put("HYD10180",8);
        map.put("HYD10170",2);
        map.put("GD0",8);
        map.put("GD1",8);
        map.put("GD2",8);
        map.put("GD3",1);
        map.put("GD4",1);
        map.put("GD5",2);
        map.put("GD6",1);
        map.put("GD7",8);
        map.put("GD8",8);
        map.put("GD9",8);
        map.put("GD10",8);
        map.put("GD11",8);
        map.put("GD120",3);
        map.put("GD121",4);
        map.put("GD122",5);
        map.put("GD123",5);
        map.put("GD124",8);
        map.put("GD125",8);
        map.put("GD1210",2);
        map.put("GD1211",5);
        map.put("GD1212",3);
        map.put("GD1213",3);
        map.put("GD1214",8);
        map.put("GD1215",3);
        map.put("GD13",8);
        map.put("GD15",8);
        map.put("GD16",8);
        map.put("GD17",2);
        map.put("GD18",1);
        map.put("GD19",1);
        map.put("GD20",1);
        map.put("GD21",1);
        map.put("GD22",1);
        map.put("GD23",2);
        map.put("GD24",2);
        map.put("GD25",2);
        map.put("GD26",2);
        map.put("GD27",5);
        map.put("GD28",5);
        map.put("GD29",2);
        map.put("GD30",8);
        map.put("GD31",2);
        map.put("GD32",1);
        map.put("GD33",8);
        map.put("GD34",2);
        map.put("GD35",8);
        map.put("GD36",8);
        map.put("GD37",2);
        map.put("GD38",2);
        map.put("GD39",2);
        map.put("GD40",1);
        map.put("GD41",2);
        map.put("GD42",2);
        map.put("GD43",1);
        map.put("GD44",8);
        map.put("GD45",8);
        map.put("GD46",5);
        map.put("GD47",8);
        map.put("GD48",2);
        map.put("GD51",8);
        map.put("GD52",1);
        map.put("GD53",1);
        map.put("GD54",2);
        map.put("GD55",2);
        map.put("GD60",8);
        map.put("GD61",8);
        map.put("GD62",3);
        map.put("XHQB1002",1);
        map.put("XHQB2001",1);
        map.put("XHQB2002",1);
        map.put("XHQB4001",1);
        map.put("XHQB2003",2);
        map.put("XHQB5010",3);
        map.put("XHQB5020",4);
        map.put("XHQB5030",5);
        map.put("XHQB5040",5);
        map.put("XHQB5050",7);
        map.put("XHQB1001",8);
        map.put("XHQB3001",8);
        map.put("XHQB4002",8);
        map.put("BXHX1",1);
        map.put("BXHX4",1);
        map.put("BXHX5",6);
        map.put("BXHX12",6);
        map.put("BXHX9",7);
        map.put("BXHX6",7);
        map.put("BXHX7",7);
        map.put("BXHX10",7);
        map.put("BXHX2",7);
        map.put("BXHX3",7);
        map.put("BXHX8",7);
        map.put("BXHX11",7);
        map.put("BXHX13",7);
        //chd状态
        map.put("CHDZXTG",1);
        map.put("CHDE1",1);
        map.put("CHDE2",1);
        map.put("CHDF1",1);
        map.put("CHDF3",1);
        map.put("CHDF5",1);
        map.put("CHDA0",1);
        map.put("CHDA1",1);
        map.put("CHDY1",1);

        map.put("CHDZXJJ",2);
        map.put("CHDCZRFQ",2);
        map.put("CHDE3",2);
        map.put("CHDF2",2);
        map.put("CHDS3",2);
        map.put("CHDAZ",2);
        map.put("CHDL2",2);
        map.put("CHDY2",2);
        map.put("CHDC1",2);
        map.put("CHDJ1",2);
        map.put("CHDJ2",2);
        map.put("CHDJ3",2);

        map.put("CHDL1",3);
        map.put("CHDY3",4);

        map.put("CHDQ1",5);
        map.put("CHDQ2",5);
        map.put("CHDQ3",5);
        map.put("CHDQ4",5);
        map.put("CHDQ5",5);
        map.put("CHDQ6",5);
        map.put("CHDJJHH",5);

        map.put("CHDXZZX",8);
        map.put("CHDF4",8);
        map.put("CHDS1",8);
        map.put("CHDS2",8);
        map.put("CHDS4",8);
        map.put("CHDA2",8);
        map.put("CHDL0",8);
        map.put("CHDL3",8);
        map.put("CHDT1",8);
        map.put("CHDT2",8);
        map.put("CHDT3",8);
        map.put("CHDE4",8);
        map.put("CHDCZRBC",8);
        //境外保险
        map.put("JWBX1",6);
        map.put("JWBX4",6);
        map.put("JWBX7",6);
        map.put("JWBX3",7);
        map.put("JWBX5",7);
        map.put("JWBX6",7);
        map.put("JWBX2",8);

        map.put("HHR_CF0",6);
        map.put("HHR_CF1",6);
        map.put("HHR_CF4",6);
        map.put("HHR_CF2",7);
        map.put("HHR_CF3",7);

        return map.get(value);
    }

}
